<!--
  #%L
  thinkbig-ui-feed-manager
  %%
  Copyright (C) 2017 ThinkBig Analytics
  %%
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  #L%
  -->
<div ng-if="vm.loading">
  <md-progress-linear md-mode="indeterminate"></md-progress-linear>
  <span class="md-body-2">{{vm.loadingMessage}}</span>
</div>

<div ng-if="vm.editSla == null && !vm.loading">
  <div ng-hide="vm.viewType != 'list'" ng-show="vm.viewType == 'list'">
    <md-list flex layout-fill class="list-item-table">
      <md-list-item dir-paginate="sla in vm.serviceLevelAgreements |orderBy:vm.paginationData.sort |filter:vm.filter|itemsPerPage:vm.paginationData.rowsPerPage"
                    pagination-id="vm.paginationId" ng-click="vm.onEditSla(sla)" current-page="vm.currentPage">
        <div layout="row" layout-fill>
          <div flex="60" layout="column" class="item-column md-list-item-text ">
            <span class="item-title">{{sla.name}}</span>
            <span class="column-title column-title-bottom">{{sla.description}}</span>
          </div>
          <div flex="40" class="item-column md-list-item-text " ng-show="sla.feedNames != ''">
            <span class="item-title">{{sla.feedNames}}</span>
            <span class="column-title column-title-bottom">相关 管道</span>
          </div>
        </div>
        <md-divider ng-if="!$last"></md-divider>
      </md-list-item>
      <md-list-item ng-show="vm.loading == false && vm.serviceLevelAgreements.length ==0">
        No Service Level Agreements
      </md-list-item>
      <md-divider></md-divider>

      <md-list-item layout-align="end center" layout-row class="pagination-list-item" ng-show="vm.serviceLevelAgreements.length > 0">
        <dir-pagination-controls pagination-id="vm.paginationId"
                                 auto-hide="false"
                                 max-size="5"
                                 direction-links="true"
                                 boundary-links="false"
                                 template-url="js/common/dir-pagination/dirPagination.tpl.html"
                                 on-page-change="vm.onPaginationChange(newPageNumber)"
                                 label="Rows per page"
                                 rows-per-page="vm.paginationData.rowsPerPage"
                                 rows-per-page-options="vm.paginationData.rowsPerPageOptions"
                                 class="pagination-row">
        </dir-pagination-controls>
      </md-list-item>
    </md-list>
  </div>
  <div ng-hide="vm.viewType != 'table'" ng-show="vm.viewType == 'table'">

    <md-table-container ng-show="vm.serviceLevelAgreements.length >0">
      <table md-table md-progress="vm.deferred.promise">
        <thead md-head md-order="vm.paginationData.sort" md-on-reorder="vm.onOrderChange">
        <tr md-row>
          <th md-column name="Name" md-order-by="name">名称</th>
          <th md-column name="Description" md-order-by="description">描述</th>
          <th md-column name="RelatedFeeds" md-order-by="feedNames">相关管道</th>
        </tr>
        </thead>
        <tbody md-body>
        <tr md-row
            ng-repeat="sla in vm.serviceLevelAgreements | orderBy: vm.paginationData.sort | filter:vm.filter | limitTo: vm.paginationData.rowsPerPage: (vm.currentPage - 1) * vm.paginationData.rowsPerPage">
          <td md-cell ng-click="vm.onEditSla(sla)">
            {{sla.name}}
          </td>
          <td md-cell ng-click="vm.onEditSla(sla)">
            {{sla.description}}
          </td>
          <td md-cell ng-click="vm.onEditSla(sla)">
            {{sla.feedNames}}
          </td>
        </tr>
        </tbody>
      </table>
    </md-table-container>

    <md-table-pagination md-limit="vm.paginationData.rowsPerPage" md-page="vm.currentPage" md-total="{{vm.serviceLevelAgreements.length}}" md-on-paginate="vm.onPaginationChange"
                         md-limit-options="[5,10,20,50,'ALL']"></md-table-pagination>


  </div>
</div>

<div ng-if="vm.editSla != null  && !vm.loading">
  <ng-include src="'js/feed-mgr/sla/service-level-agreement-form.html'"></ng-include>


  <div>

  </div>
</div>

